<template>
  <v-card>
      <v-flex xs12 sm10>
        <!-- 这里的 v-tree 是一个自定义组件 -->
        <!-- 这里的组件采用的是全局引入， -->
        <v-tree url="/item/category/list"
                :isEdit="isEdit"
                @handleAdd="handleAdd"
                @handleEdit="handleEdit"
                @handleDelete="handleDelete"
                @handleClick="handleClick"
        />
      </v-flex>
  </v-card>
</template>

<script>
  import {treeData} from "../../mockDB";
  export default {
    name: "category",
    data() {
      return {
        treeData,
        isEdit:true
      }
    },
    methods: {
      handleAdd(node) {
          this.$http({
              method: 'post',
              url: '/item/category',
              data: this.$qs.stringify(node)
          }).then(() => {
              this.$message.success("新增成功！");
          })
          .catch(() => {
              this.$message.error("新增失败！");
          });
      },
      handleEdit(node) {
        this.$http({
            method: 'put',
            url: '/item/category',
            data: this.$qs.stringify(node)
        }).then(() => {
            this.$message.success("修改成功！");
        })
        .catch(() => {
            this.$message.error("修改失败！");
        });
      },
      handleDelete(node) {
        this.$http({
            method: 'post',
            url: '/item/category/delete',
            data: this.$qs.stringify(node)
        }
        ).then(() => {
            this.$message.success("删除成功！");
        })
        .catch(() => {
            this.$message.error("删除失败！");
        });
      },
      handleClick(node) {
        console.log(node)
      }
    }
  };
</script>

<style scoped>

</style>
